//
//  ViewController.m
//  选择国旗
//
//  Created by song on 15/1/20.
//  Copyright (c) 2015年 song. All rights reserved.
//

#import "ViewController.h"
#import "JOFlag.h"
#import "JOFlagView.h"

@interface ViewController () <UIPickerViewDataSource , UIPickerViewDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}

-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    return self.flags.count;
}


-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
    JOFlagView *flagview =[JOFlagView flagView:(JOFlagView *)view];
    
    flagview.flag = self.flags[row];
   
    return flagview;
}

-(CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component
{
    return  50;
}

-(NSArray *)flags
{
    if(_flags ==nil)
    {
        NSArray *array =[NSArray arrayWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"flags.plist" ofType:nil]];
        NSMutableArray *marray =[NSMutableArray array];
        for(NSDictionary *dic in array)
        {
            JOFlag *flag =[JOFlag flagWithDict:dic];
            [marray addObject:flag];
        }
        _flags =marray;
    }
    
    return _flags;
}

@end
